package com.hubu.parking.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hubu.parking.common.BaseResponse;
import com.hubu.parking.common.ResultUtils;
import com.hubu.parking.model.dto.park.EndToSpotDto;
import com.hubu.parking.model.dto.park.PageListRecordRequest;
import com.hubu.parking.model.dto.park.StartToSpotDto;
import com.hubu.parking.model.vo.ParkingDurationVo;
import com.hubu.parking.model.vo.ParkingRecordVo;
import com.hubu.parking.service.ParkingRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 实际停车记录接口
 */
@RestController
@RequestMapping("/record")
@Slf4j
public class RecordController {

    @Resource
    private ParkingRecordService recordService;

    /**
     * 查询
     *
     * @return
     */
    @PostMapping("/list")
    public BaseResponse<Page<ParkingRecordVo>> listSpot(@RequestBody PageListRecordRequest pageRequest) {
        return ResultUtils.success(recordService.pageListParkingRecord(pageRequest));
    }

    /**
     * 查询
     *
     * @param request 筛选参数
     * @return
     */
    @PostMapping("/listNoPage")
    public BaseResponse<List<ParkingRecordVo>> listRecordNoPage(@RequestBody PageListRecordRequest request) {
        return ResultUtils.success(recordService.listRecordNoPage(request));
    }

    /**
     * 查询停车时长分布
     *
     * @return
     */
    @PostMapping("/duration")
    public BaseResponse<ParkingDurationVo> listDuration() {
        return ResultUtils.success(recordService.listDuration());
    }

    /**
     * 开始停车
     *
     * @return
     */
    @PostMapping("startToSpot")
    public BaseResponse add(@RequestBody StartToSpotDto dto) {
        recordService.startToSpot(dto);
        return ResultUtils.success(null);
    }

    /**
     * 结束停车
     *
     * @return
     */
    @PostMapping("endToSpot")
    public BaseResponse add(@RequestBody EndToSpotDto dto) {
        recordService.endToSpot(dto);
        return ResultUtils.success(null);
    }
}
